package de.clapp;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import de.clapp.club.ClubListFragment;
import de.clapp.map.MyMapFragment;
import de.clapp.newsfeed.NewsfeedFragment;
import de.clapp.qrcode.QRCodeScanFragment;
import de.clapp.toolkit.Tools;

public class GeneralMainFragment extends Fragment
{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        setHasOptionsMenu(true);
        View view = inflater.inflate(R.layout.fragment_general, container, false);
        return view;
    }
    
    @Override
    public void onResume()
    {
        super.onResume();
        Tools.replaceFragment(this, R.id.generalLayout, new NewsfeedFragment());
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
    {
        menu.clear();
        MenuInflater menuInflater = getActivity().getMenuInflater();
        menuInflater.inflate(R.menu.menu_general, menu);
        menu.hasVisibleItems();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        
        Fragment newFragment = null;
        switch (item.getItemId())
        {
            case R.id.action_general_news:
                newFragment = new NewsfeedFragment();
                break;

            case R.id.action_general_map:
                newFragment = new MyMapFragment();
                break;

            case R.id.action_general_friends:
                break;

            case R.id.action_general_clublist:
                newFragment = new ClubListFragment();
                break;

            case R.id.action_general_favorites:
                newFragment = new QRCodeScanFragment();
                break;

            case R.id.action_general_profile:
                break;
        }

        if (newFragment != null)
        {
            Tools.replaceFragment(this, R.id.generalLayout, newFragment);
        }
//        Toast.makeText(getActivity(), getString(R.string.action_selected, item.getTitle()), Toast.LENGTH_SHORT).show();

        return super.onOptionsItemSelected(item);
    }
}